package org.hjq.controller;

import org.hjq.entity.Order;
import org.hjq.entity.PageVO;
import org.hjq.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping("order")
public class OrderController {

   @Autowired
   private IOrderService orderService;

    @GetMapping("{id}")
    public Order queryOrderByOrderId(@PathVariable("id") Long id) {
        // 根据id查询订单并返回
        return orderService.queryOrderById(id);
    }
    @GetMapping
    public PageVO queryOrder(@PathParam("limit")Long limit, @PathParam("size")Long size){
        // 分页查询订单
        return orderService.queryOrder(limit,size);
    }
    @PutMapping
    public Boolean update(@RequestBody Order order){
        // 根据id更新订单
        return orderService.saveOrUpdate(order);
    }
    @DeleteMapping("{id}")
    public Boolean deleteById(@PathVariable Long id){
        // 根据id删除订单
        return orderService.removeById(id);
    }
    @PostMapping
    public Boolean saveOrder(@RequestBody Order order){
        // 新增订单
        return orderService.saveOrUpdate(order);
    }
}
